﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;

namespace StyleMVVM.DependencyInjection
{
	/// <summary>
	/// This is a life cycle container class that shares the export per Injection (i.e. for this activation and all it's children share the export)
	/// </summary>
	public sealed class SharedPerInjectionContainer : ILifeCycleContainer
	{
		private string key = Guid.NewGuid().ToString();

		public object RetrieveObject(IExportStrategy strategy,
		                             ExportLifeCycleMethod exportMethod,
		                             IDependencyInjectionContainer container,
		                             IInjectionContext injectionContext,
		                             [ReadOnlyArray] object[] constructorParams)
		{
			object returnValue = injectionContext.GetCustomData(key);

			if (returnValue == null)
			{
				returnValue = exportMethod(injectionContext, constructorParams);

				if (returnValue != null)
				{
					injectionContext.SetCustomData(key, returnValue);
				}
			}

			return returnValue;
		}

		public void Shutdown()
		{
			
		}
	}
}